package com.xushi.controller;

import com.xushi.bean.ApplyPriceResult;
import com.xushi.service.ApplyPriceService;
import com.xushi.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/applyPrice")
public class ApplyPriceController {
    @Autowired
    private ApplyPriceService applyPriceService;

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/submit")
    @ResponseBody
    public ApplyPriceResult applyPrice(@RequestParam String openId,
                                       @RequestParam int activityId) {
        ApplyPriceResult applyPriceResult = applyPriceService.applyPrice(activityId, openId);
        return applyPriceResult;
    }

    @PostMapping("/uploadUserInfo")
    @ResponseBody
    public Map<String, Object> uploadUserInfo(@RequestParam String trueName, @RequestParam String openId,
                                              @RequestParam String phoneNumber) {
        userInfoService.saveOrUpdateUserInfo(openId, trueName, phoneNumber);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("message", "upload user info successfully!");
        return result;
    }
}
